package sg.edu.nus.iss.umpire.email;

import sg.edu.nus.iss.umpire.support.HttpMethod;
import sg.edu.nus.iss.umpire.support.Service;
import sg.edu.nus.iss.umpire.support.ServiceConfig;
import sg.edu.nus.iss.umpire.support.ServiceContext;

import com.google.appengine.api.backends.BackendServiceFactory;
import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.appengine.api.taskqueue.TaskOptions.Method;

@SuppressWarnings("serial")
@ServiceConfig(path = "submitreminderjob", method = HttpMethod.GET)
public class CompetitionReminderJobServlet implements Service {

	@Override
	public String serve(ServiceContext ctx) throws Exception {
		queueCompetitionReminderJob();
		return null;
	}

	
	private void queueCompetitionReminderJob()
	{
	  	Queue queue = QueueFactory.getQueue("CompetitionReminderQueue");
	  	TaskOptions taskOptions = TaskOptions.Builder.withUrl("/umpire/processreminderrequest")
	  	                          .header("Host", BackendServiceFactory.getBackendService().getBackendAddress("competition-reminder-backend"))
	  	                          .method(Method.POST);
	  	queue.add(taskOptions);
	}

}
